﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class denglu : System.Web.UI.Page
{
    private static string sqlconn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString().Trim();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string id = txtID.Text.Trim();
        string ps = txtPS.Text.Trim();
        SqlConnection conn = new SqlConnection(sqlconn);
        try
        {
            conn.Open();
            string selectA = "select count(*) UserID from UserInfo where UserID='" + id + "'and UserPW='" + ps + "'";
            string selectB = "select count(*) UserID from Admin where AdminID='" + id + "'and  AdminPW='" + ps + "'";
            SqlCommand coma = new SqlCommand(selectA, conn);
            SqlCommand comb = new SqlCommand(selectB, conn);
            int A = (int)coma.ExecuteScalar();
            int B = (int)comb.ExecuteScalar();
            if (ddlUser.SelectedIndex == 0)
            {
                if (B == 1)
                {
                    Response.Write("<script> alert(\"用户名不存在\")</script>");

                }
                else
                {
                    Session["id"] = id;
                    //Response.Write("<script> alert(\"登陆成功\")</script>");
                    Response.Redirect("~/Start.aspx");
                }
            }
            else
                if (A > 0)
                {
                    Response.Write("<script>window.alert(\"用户不存在！\")</script>");

                }
                else
                {
                    Session["id"] = id;
                    //Response.Write("<script> alert(\"登陆成功\")</script>");
                    Response.Redirect("~/Start1.aspx");

                }
        }
        catch (SqlException ee)
        {
            throw new Exception(ee.Message);
        }
        finally
        {
            conn.Close();
        }
        if (ddlUser.SelectedValue == "manager")
        {
            Response.Redirect("start1.aspx?id=" + txtID.Text);
        }
        else
        {
            Response.Redirect("start.aspx?id=" + txtID.Text);
        }
    }
}